package com.dididoctor.doctor.Activity.Usercentre.Authentication;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.dididoctor.doctor.Activity.Usercentre.Userinfo.UserInfoActivity;
import com.dididoctor.doctor.MV.adapter.CommonAdapter;
import com.dididoctor.doctor.MV.adapter.ViewHolder;
import com.dididoctor.doctor.R;
import com.dididoctor.doctor.Ui.cityList.CityBean;

import java.util.List;


/**
 * @version 2.0
 * @类描述：
 * @项目名称：ddgh
 * @类名称： HotCityAdapter
 * @包名称： com.dididoctor.patient.Activity.Userinfo
 * @创建人： liying
 * @创建时间：2016/4/14 17:16
 * @修改人：
 * @修改时间：2016/4/14 17:16
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class HotCityAdapter extends CommonAdapter<CityBean> {
    private Context context;
    private boolean isuserinfo;

    public HotCityAdapter(Context context, List<CityBean> datas, boolean isuserinfo) {
        super(context, datas, R.layout.item_hot_city);
        this.context = context;
        this.isuserinfo = isuserinfo;
    }

    @Override
    public void convert(int position, ViewHolder helper, final CityBean item) {

        if (item != null && !item.equals("")) {
            helper.getView(R.id.btn_hot_city).setVisibility(View.VISIBLE);
            helper.setText(R.id.btn_hot_city, item.getCityName());
        } else {
            helper.getView(R.id.btn_hot_city).setVisibility(View.GONE);
        }

        helper.getView(R.id.btn_hot_city).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent;
                if (isuserinfo) {
                    intent = new Intent(context, UserInfoActivity.class);
                } else {
                    intent = new Intent(context, SelectAddressActivity.class);
                }
                intent.putExtra("hotcity", item);
                ((Activity) context).setResult(Activity.RESULT_OK, intent);
                ((EditCityView) context).finishActivity();
            }
        });

    }
}
